retAddr
parameter to OTBind
, and checking
that the resulting fPort
field matches the port you requested.
One common cause of this is that the port is still in use by your own application
because of the IP reuse address delay. You can eliminate this delay using the code
described in Q&A NW 28 "TCP Application Acquires Different Port Address After Relaunch".
That Q&A is
specific to TCP endpoints, but the technique works for both TCP and UDP endpoints.OTBind
. General purpose
programs that
want to listen for connections/datagrams should always bind to kOTAnyInetAddress
(ie 0), not to a specific IP address. On a multi-homed machine, if you bind to a
specific address, you will only receive connections/datagrams addressed to that IP
number. This is useful if you're writing a server that reacts differently depending
on which IP address it receives a connection on, but most general purpose code should
not care which IP address the connection/datagram was sent to.
In this specific case, if you bind a UDP endpoint to a specific IP address, you will
not receive broadcast packets on that endpoint because they were not sent to the
specific IP address you bound to.